<?php
/**
 * Created by PhpStorm.
 * User: lcz
 * Date: 2018/4/11
 * Time: 14:07
 * 用户
 */

namespace app\mobile\controller;

use app\common\controller\Mobile;
use app\common\model\AppDownload;
use think\Session;
use think\Db;

class User extends Mobile {
	
	/**
	 * 登录
	 * @return mixed
	 */
	public function login(){
		$merid = Session::get('merid');
		$where['merid'] = $merid;
        if(strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone')||strpos($_SERVER['HTTP_USER_AGENT'], 'iPad')){
        	//苹果下载
	        $where['app_type'] = AppDownload::TYPE_IOS;
            $row = Db::name('appDownload')->where($where)->find();
        }else{
	        $where['app_type'] = AppDownload::TYPE_ANDROID;
        	//安卓下载
            $row = Db::name('appDownload')->where($where)->find();
        }
		return $this->fetch('login',[
			'title' => '登录',
			'downUrl' => isset($row['url'])?$row['url']:'',
		]);
	}
	
	/**
	 * 注册
	 */
	public function register(){
		$merid = Session::get('merid');
		$where['merid'] = $merid;
		if(strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone')||strpos($_SERVER['HTTP_USER_AGENT'], 'iPad')){
			//苹果下载
			$where['app_type'] = AppDownload::TYPE_IOS;
			$row = Db::name('appDownload')->where($where)->find();
		}else{
			$where['app_type'] = AppDownload::TYPE_ANDROID;
			//安卓下载
			$row = Db::name('appDownload')->where($where)->find();
		}
		
		$rmobile = '';
		if(input('rmobile')){
			$rmobile = input('rmobile');
		} elseif(Session::get('recommend_mobile')) {
			$rmobile = Session::get('recommend_mobile');
		}
		return $this->fetch('register', [
			'title' => '注册',
			'downUrl' => isset($row['url'])?$row['url']:'',
			'rmobile' => $rmobile
		]);
	}
	
	/**
	 * 通过手机号重置密码
	 */
	public function forgetPasswrod(){
		return $this->fetch();
	}
	
	/**
	 * 我的下级
	 */
	public function sons(){
		return $this->fetch('sons',[
			'title' => '我的下级',
		]);
	}
	
	/**
	 * 我的二维码
	 */
	public function qrcode(){
		return $this->fetch('qrcode', [
			'title' => '我的二维码',
			'data' => input(),
		]);
	}
	
	/**
	 * 修改登录密码
	 */
	public function changePassword(){
		return $this->fetch('changePassword',[
			'title' => '修改登录密码',
			'type' => 'password',
		]);
	}
	
	
	/**
	 * 修改支付密码
	 */
	public function changePayPassword(){
		return $this->fetch('changePassword',[
			'title' => '修改支付密码',
			'type' => 'pay_password',
		]);
	}
	
	/**
	 * 修改支付密码
	 */
	public function findPassword(){
		return $this->fetch('findPassword',[
			'title' => '找回密码',
		]);
	}
	
	/**
	 * 修改支付密码
	 */
	public function resetPayPassword(){
		return $this->fetch('resetPayPassword',[
			'title' => '重置支付密码',
		]);
	}

	public function token(){
		Session::set('token', input('post.token'));
	}

	public function logout(){
		Session::set('token', null);
	}
	
	public function verified(){
		return $this->fetch('verified', [
			'title' => '实名认证'
		]);
	}
	
	public function sign(){
		return $this->fetch('sign', [
			'title' => '签到'
		]);
	}
}
